package com.example.hp.yuejian5.model;



import com.example.hp.yuejian5.RetrofitListener.RetrofitListener;
import com.example.hp.yuejian5.bean.LoginBean;
import com.example.hp.yuejian5.service.RetrofitService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.hp.yuejian5.other.url.INDEXURL;

public class UserModel{
    protected Retrofit retrofit;
    protected RetrofitService userService;
    public UserModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(INDEXURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        userService=retrofit.create(RetrofitService.class);
    }
    public void userLogin(String name,String password,final RetrofitListener listener)
    {

        Call<LoginBean> call= userService.login(name,password);
        call.enqueue(new Callback<LoginBean>() {
            @Override
            public void onResponse(Call<LoginBean> call, Response<LoginBean> response) {
                listener.onSuccess(response.body(),1);
            }
            @Override
            public void onFailure(Call<LoginBean> call, Throwable t) {
                    listener.onFail();
            }
        });
    }


}
